﻿   
   //有关div操作的一些方法
   
   ///cdh 2007-8-30
   ///在屏幕中间显示DIV
   ///<parmars DivId>层的ID
   function ShowDiv(DivId)
   {
        var width = parseInt(screen.availWidth); ///屏幕宽度
        var height = parseInt(screen.availHeight); //屏幕高度
        var objDiv = document.getElementById(DivId);
        var divHeight = parseInt(objDiv.style.height); //div的高度
        var divWidth = parseInt(objDiv.style.width);//div的宽度
        
        objDiv.style.display = "block";
        objDiv.style.left = (width-divWidth)/2;
        objDiv.style.top = (height-divHeight)/2-divHeight/2;

        SetTextBoxValueEmptied();
        return false;
   } 
   
   ///
   ///隐藏DIV
   ///
   function HiddenDiv(DivId)
   {
       document.getElementById(DivId).style.display = "none";
       SetTextBoxValueEmptied();
   }
   
   ///
   ///把textbox,textarea的值置为空
   ///
   function SetTextBoxValueEmptied()
   {
       var TextBoxList= document.getElementsByTagName("input"); //要清空值的类型
       var ControlType=new Array("input","textarea");//要清空值的类型
       
       for(var j=0;j<ControlType.length;j++)
       {
           var items = document.getElementsByTagName(ControlType[j]);
           for(var i=0;i<items.length;i++)
           {
              if(items[i].type!="hidden" && items[i].type!="button")
              {
                 //items[i].value="";
              }
           }
       }
   }
   
   ///
   ///拖动层
   ///
   function neverDragDivision(fObj){
   with (this)
   {
       if (!fObj) return; 
          this.bDraged = false;
       this.oDragOrig = fObj;
       oDragOrig.style.cursor = "move";
       oDragOrig.onmousedown = function() {
       var ofs = Offset(oDragOrig);
       oDragOrig.style.position = "absolute";
       oDragOrig.style.left = ofs.l;
       oDragOrig.style.top = ofs.t;
       oDragOrig.X = event.clientX - ofs.l;
       oDragOrig.Y = event.clientY - ofs.t;
       bDraged = true; 
  };
 
  oDragOrig.onmousemove = function() {
    if (!bDraged) return;
    oDragOrig.setCapture();  
    oDragOrig.style.left = event.clientX - oDragOrig.X;  
    oDragOrig.style.top = event.clientY - oDragOrig.Y;
 };
 
 oDragOrig.onmouseup = function(){  
    bDraged = false;  
    oDragOrig.releaseCapture();
  };
  
 function Offset(e) {  
    var t = e.offsetTop;  
    var l = e.offsetLeft;  
    var w = e.offsetWidth;  
    var h = e.offsetHeight;  
    
     while(e=e.offsetParent) 
     {  
       t+=e.offsetTop;  
       l+=e.offsetLeft;  
     }
      return { t:t, l:l, w:w, h:h }
   };
 }
};


///
///移动层
///
function MoveDiv(DivId)
{
     var objDiv = document.getElementById(DivId);
     new neverDragDivision(objDiv);
}

///设置控件可用
function SetControlEnable(itemid)
{
    document.getElementById(itemid).disabled=false;
}

///设置控件不可用
function SetControlUnEnable(itemId)
{
    document.getElementById(itemid).disabled=true;
}

///弹出确认对话框
function WindowConfirm(strMsg)
{
    return window.confirm(strMsg);
}

///关闭窗口
function WindowClose()
{
    if(WindowConfirm("确认关闭?"))
    {
       self.close();
    }
}

///删除多个记录时提示信息
function ConfirmDeleteSomeRecord()
{
    //checkbox
    var checkBoxList= document.getElementsByTagName("input"); //找出所有的INPUT对象
    var number=0;
   
    for( var i=0;i<checkBoxList.length;i++)
    {
        if(checkBoxList[i].type=="checkbox")
        {
            if(checkBoxList[i].checked)
            {
                number++;
            }
        }
    }
    
    if(number==0)
    {
        alert("请选择要删除的项!");
        return false;
    }
    else
    {
        return window.confirm("确认删除所选的"+number+"项?");
    }
}

///在屏幕中间打开窗口
///width窗口宽度
///url打开路径
///height窗口高度
function OpenWindow(objWidth,objHeight,url)
{
      var width = parseInt(screen.availWidth); ///屏幕宽度
      var height = parseInt(screen.availHeight); //屏幕高度
      var lef= (width-objWidth)/2;
      var top= (height-objHeight)/2;
      var parmars="width="+objWidth+"px,height="+objHeight+"px,depended=1,left="+lef+",top="+top;
      window.open(url,'',parmars);
}


